<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="ss" uri="/WEB-INF/stripes-security.tld" %>
<s:layout-render name="/layout.jsp" title="Creature types">
    <s:layout-component name="menu"></s:layout-component>
    <s:layout-component name="main_content">
        <s:useActionBean var="ab" beanclass="cz.muni.fi.pa165.creatures.web.CreatureTypeActionBean"/>    
        <s:useActionBean var="wab" beanclass="cz.muni.fi.pa165.creatures.web.WeaponsActionBean"/>    
        <div class="main-content">
            <div class="content">
                 <ss:secure roles="admin">
                <img src="${pageContext.request.contextPath}/images/banner-admin.png" alt="Banner" id="banner"/>                
                </ss:secure>
                <ss:secure roles="user">
                <img src="${pageContext.request.contextPath}/images/banner-scout.png" alt="Banner" id="banner"/>                
                </ss:secure>
                <h1><f:message key="edit.creature_type"/></h1>
                <s:form beanclass="cz.muni.fi.pa165.creatures.web.CreatureTypeActionBean">
                    <ss:secure roles="admin">
                    <%@include file="/forms/createCreatureType.jsp" %>
                    <s:submit name="save"><f:message key="edit"/></s:submit>
                    </ss:secure>
                    <s:submit name="cancel"><f:message key="cancel"/></s:submit>
                </s:form>  
                
                <c:if test="${ab.numOfAssociatedWeapons < 3 && wab.count > 0}">
                
                <s:form beanclass="cz.muni.fi.pa165.creatures.web.CreatureTypeActionBean">
                    <ss:secure roles="admin">
                    <%@include file="/forms/createCreatureTypeWeapon.jsp" %>
                    <s:submit name="assignWeapon"><f:message key="assign_weapon"/></s:submit>
                    </ss:secure>
                </s:form>
                </c:if>    
                <c:if test="${ab.numOfAssociatedWeapons >= 3}">
                    <div>
                        <f:message key="there_are_to_many_associated_weapons"/>
                        
                    </div>
                </c:if>
                    <table>
                        <thead>
                            <tr>
                                <th><s:label name="creatureTypeWeaponDTO.weapon"/></th>
                                <th><s:label name="creatureTypeWeaponDTO.efficiency"/></th>
                                <th><f:message key="actions"/></th>
                            </tr>
                        </thead>
                         <c:forEach items="${ab.effectivity}" var="creatureTypeWeaponDTO">
                                        <tr>
                                            <td><c:out value="${creatureTypeWeaponDTO.weaponName}"/></td>
                                            <td><c:out value="${creatureTypeWeaponDTO.efficiency}"/></td>
                                            <td>  <ss:secure roles="admin"> 
                                                <s:link beanclass="cz.muni.fi.pa165.creatures.web.CreatureTypeActionBean" event="deleteWeapon">
                                                    <s:param name="weaponId" value="${creatureTypeWeaponDTO.weaponId}"/>
                                                    <s:param name="creatureTypeId" value="${creatureTypeWeaponDTO.creatureTypeId}"/>
                                                    <f:message key="remove"/></s:link>
                                                </ss:secure>
                                            </td>              
                                        </tr>
                         </c:forEach>
                    </table>
            </div>
        </div>
    </s:layout-component>
</s:layout-render>
